<!DOCTYPE HTML>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>提现</title>
	<link rel="stylesheet" type="text/css" href="../../../css/api.css" />
	<style>
		body {
			width: 100%;
			height: 100%;
			background: #f5f5f5;
			padding-bottom: 50px;
		}

		#app .header {
			height: 44px;
			line-height: 44px;
			text-align: center;
			background-color: #ffffff;
			font-size: 16px;
			position: fixed;
			top: 0;
			right: 0;
			left: 0;
			padding: 0 15px;
			display: flex;
			align-items: center;
			justify-content: space-between;
		}

		#app .header img {
			width: 22px;
			height: 22px;
		}

		#app .info {
			padding: 15px 15px 0;
		}

		#app .info>.tit {
			font-size: 14px;
			color: #000;
			line-height: 14px;
			margin-bottom: 10px;
		}

		#app .info .money_ {
			width: 100%;
			height: 60px;
			background-color: #ffffff;
			border-radius: 10px;
			display: flex;
			align-items: center;
			padding: 0 0 0 25px;
			font-size: 25px;
			color: #000;
			font-weight: bold;
			box-sizing: border-box;
			margin-bottom: 5px;
		}

		#app .info .max {
			color: #ff3a24;
			font-size: 12px !important;
			margin-bottom: 20px;
		}

		#app .info .money_ input {
			width: 100%;
			flex: 1;
			font-size: 25px;
			color: #000;
			font-weight: bold;
			margin-left: 10px;
			line-height: 25px;
		}

		input::-webkit-input-placeholder {
			color: #999999;
			font-size: 16px;
			text-align: left;
			font-weight: 500;
		}

		.btns {
			margin-top: 40px;
		}

		.btns div {
			width: 100%;
			height: 50px;
			line-height: 50px;
			text-align: center;
			border-radius: 100px;
			font-size: 16px;
		}

		.btns div.btns_bg {
			background: #ccc;
			color: #fff;
			font-weight: bold;
			margin-bottom: 20px;
		}

		.btns div.btns_top {
			background-image: linear-gradient(45deg,
		#ff3a24 0%,
		#ff5340 100%);
			color: #ffffff;
			font-weight: bold;
			margin-bottom: 20px;
		}

		.btns div.btns_bot {
			background-color: #ffffff;
			color: #333;
		}

		.times {
			font-size: 11px;
			color: #666666;
			line-height: 11px;
			margin-top: 10px;
		}

		.type {
			border-radius: 10px;
			margin: 0 15px;
			background: #ffffff;
			padding: 15px;
			display: flex;
			justify-content: space-between;
			align-items: center;
		}

		.type .name {
			margin: 0 15px;
			flex: auto;
		}

		.type img:first-child {
			height: 40px;
			width: 40px;
		}

		.type img:last-child {
			height: 10px;
			width: 6;
		}
	</style>
</head>

<body>
	<div id="app">
		<div class="header">
			<img src="../../../image/icon_return.png" alt="" onclick="back()">
			提现
			<div onclick="transfer_list()">明细</div>
		</div>

		<div class="type" onclick="bind_alipay()">
			<img src="../../../image/me/weixinicon.png" alt="" class="type_img">
			<div class="name">
				<div>请绑定</div>
			</div>
			<img src="../../../image/icon_more.png" alt="">
		</div>

		<div class="info">
			<div class="tit">提现金额</div>
			<div class="money_">
				<span>￥</span>
				<input id='num' oninput="changes()" type="number" placeholder="请输入提现金额">
			</div>
			<div class="max"></div>
			<div class="times">到账时间：1-3工作日</div>

			<div class="btns">
				<div class="btns_bg" onclick=" transFer() ">确认提现</div>
				<div class="btns_bot" tapmode onclick="openKefuFun() ">联系客服</div>
			</div>
		</div>
	</div>
</body>
<script type="text/javascript" src="../../../script/api.js"></script>
<script type="text/javascript" src="../../../script/zepto.js"></script>
<script type="text/javascript">
	let num;
	let system_info, member_info;
	let click = true;
	apiready = function () {
		resume("income_withdraw");

		num = $api.dom("#num")
		$api.dom('.type').style.marginTop = $api.fixStatusBar($api.dom('.header')) + 15 + 'px';

		api.addEventListener({
			name: 'viewappear'
		}, function (ret, err) {
			getMemberInfo()
		});

		api.addEventListener({
			name: 'keyback'
		}, function (ret, err) {
			if (api.frames().findIndex(item => {
				return item.name == "income_changePhone"
			}) != -1) {
				api.closeFrame({
					name: "income_changePhone"
				});
				return;
			} else {
				back();
			}
		});

		system_info = api.getGlobalData({
			key: 'system_info'
		})

		$api.html($api.dom(".max"), '今日最大提现金额' + system_info.withdraw_max + '元');
		getMemberInfo()

		if (system_info.withdraw_type) {
			$api.dom(".type_img").src = "../../../image/withdraw_icon_alipay_normal.png"
		} else {
			$api.dom(".type_img").src = "../../../image/me/weixinicon.png"
		}
	};


	function getMemberInfo() {
		$api.ajax({
			url: 'api/member/info',
			method: 'get',
		}, function (ret) {
			api.setGlobalData({
				key: 'member_info',
				value: ret.data.info,
			});
			member_info = ret.data.info
			if (system_info.withdraw_type) {
				if (member_info.alipay_logon_id) {
					$api.html($api.dom(".name"), `<div>` + member_info.alipay_real_name + `</div><div>` + member_info.alipay_logon_id + `</div>`);
				}
			} else {
				$api.html($api.dom(".name"), `<div>` + member_info.nick_name + `</div>`);
			}
		});
	}
	//选择提现方式  1:支付宝  0:微信

	function transfer_list() {
		api.openTabLayout({
			name: 'transfer_list',
			url: './transfer_list.html',
			useWKWebView: true,
			bgColor: '#fff',
		})
	}
	function bind_alipay() {
		// console.log(JSON.stringify(system_info.withdraw_type))
		if (system_info.withdraw_type) {
			api.openTabLayout({
				name: 'bind_alipay',
				url: '../setting/bind_alipay.html',
				useWKWebView: true,
				bgColor: '#fff',
			})
		}
	}

	function income_changePhone() {
		api.openFrame({
			reload: true,
			name: 'income_changePhone',
			url: './income_changePhone.html',
			bgColor: "rgba(0,0,0,0.2)",
			animation: {
				type: "none",
			},
			pageParam: {
				type: 0
			}
		});
	}

	function back() {
		api.closeWin({
		});
	}

	function changes() {
		$api.val(num, ($.trim($api.val(num)).match(/^\d*(\.?\d{0,1})/g)[0]) || null);
		if (from() == 10) {
			$api.addCls($api.dom('.btns div:first-child'), 'btns_top');
		} else {
			$api.removeCls($api.dom('.btns div:first-child'), 'btns_top');
		};
	}

	function from() {
		if ($.trim($api.val(num)).length < 1) {
			return 0;
		}
		if (system_info.withdraw_type) {
			if (!member_info.alipay_logon_id) {
				return 2;
			}
		};
		return 10;

	}

	function transFer() {
		switch (from()) {
			case 0:
				api.toast({
					msg: '请输入提现金额',
					duration: 2000,
					location: 'middle'
				});
				break;
			case 2:
				api.toast({
					msg: '请绑定支付宝',
					duration: 2000,
					location: 'middle'
				});
				break;
			case 10:
				if($.trim($api.val($api.dom("#num"))) < 1){
					api.toast({
							msg: '账户余额没有满足最低提现金额（1元）不能提现',
							duration: 3000,
							location: 'middle'
						});
					break;
			};
			$api.ajax({
				url: 'api/member/info',
				method: 'get',
			}, function (ret) {
					api.setGlobalData({
							key: 'member_info',
							value: ret.data.info,
					});
					member_info = ret.data.info
					if (member_info.mobile.length == 0) {
							setTimeout(() => {
									income_changePhone();
							}, 500);
					} else {
						$api.ajax({
								url: 'api/member/transfer',
								method: 'POST',
								data: {
									values: {
										amount: $.trim($api.val($api.dom("#num"))),
										type: system_info.withdraw_type,
									}
								}
						}, function (ret) {

							$api.ajax({
								url: 'api/member/info',
								method: 'get',
							}, function (ret) {
									api.setGlobalData({
											key: 'member_info',
											value: ret.data.info,
									});
									api.execScript({
											name: 'root',
											frameName:'me_main',
											script: "getBill()"
									});
							})
							api.toast({
								msg: "提现申请成功",
								duration: 2000,
								location: 'middle'
							});

							setTimeout(() => {
								back()
							}, 1000);
						});
					}
				});
				break;
		}
	}
	// 联系客服
	function openKefuFun(){
			api.openTabLayout({
					name: 'exclusive',
					url: '../../me/exclusive.html',
					useWKWebView: true,
					bgColor: '#fff',
			});
	}
</script>

</html>
